{% load staticfiles %}
<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<!-- Tell the browser to be responsive to screen width -->
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="">
	<meta name="author" content="">
	<link rel="icon" type="image/png" sizes="16x16" href="{% static 'img/favicon.ico' %}" />
	<title>数据质量检核平台</title>


	<link rel="stylesheet" type="text/css" href="{% static 'check/css/admin/bootstrap.min.css' %}" />
	<link rel="stylesheet" type="text/css" href="{% static 'check/css/admin/style.css' %}" />
	<link rel="stylesheet" type="text/css" href="{% static 'css/animate.css' %}" />
	<link rel="stylesheet" type="text/css" href="{% static 'css/fonts.css' %}" />
	<link rel="stylesheet" type="text/css" href="{% static 'css/icons.css' %}" />

	<link rel="stylesheet" type="text/css" href="{% static 'CodeMirror/lib/codemirror.css' %}" />
	<link rel="stylesheet" type="text/css" href="{% static 'CodeMirror/theme/eclipse.css' %}" />

	<style>
		.dataTables_filter {
			margin-top: -45px;
		}

		.dataTables_wrapper .dataTables_filter input {
			width: 300px;
		}

		td.details-control {
			background: url("{% static 'img/details_open.png' %}") no-repeat center center;
			cursor: pointer;
		}

		tr.shown td.details-control {
			background: url("{% static 'img/details_close.png' %}") no-repeat center center;
		}
	</style>
</head>

<body>
	<!-- head star -->
	<div class="tnav row wrapper border-bottom white-bg page-heading">
		<div class="col-sm-4">
			<h2 class="fl" style="color: #007bff;font-size: 21px;font-weight:500">数据质量检核规则库</h2>
			<ol class="breadcrumb fl">
				<li><a href="../../data/index">主页</a></li>
				<li><strong>检核规则库</strong></li>
			</ol>
		</div>
	</div>
	<!-- head end -->

	<!-- table star -->
	<div class="row col-lg-12">
		<div class="wrapper wrapper-content animated fadeInUp">
			<div class="ibox">
				<div class="ibox-title">
					<h5>{{ source_system }}公司-新增检核规则</h5>
					<div class="ibox-tools rboor">
						<!-- <a href="javascript:void(0);" id="commit" onclick="fun_commit()" class="btn btn-primary btn-xs p310"><i class="im-reply"></i> 提交</a> -->
						<a href="#" id="commit" class="btn btn-primary btn-xs p310"><i class="im-reply"></i> 提交</a>
					</div>
				</div>

				<div class="ibox-content">
					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">数据标准</label>
							<input id="check_item" type="text" class="form-control" style="width: 400px;">
						</div>
					</div>

					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">目标表</label>
							<input id="target_table" type="text" class="form-control" style="width: 400px;">
						</div>
					</div>

					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">是否风险集市</label>
							<select id="risk_market" class="custom-select">
								<option value="是">是</option>
								<option value="否">否</option>
							</select>
						</div>
					</div>

					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">问题分类</label>
							<input id="problem_type" type="text" class="form-control" style="width: 400px;">
						</div>
					</div>

					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">源系统数据库</label>
							<input id="db" type="text" class="form-control" style="width: 400px;">
						</div>
					</div>

					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">检核逻辑</label>
							<textarea id="code" name="code" type="text" class="form-control"></textarea>
						</div>
					</div>

					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">备注</label>
							<textarea id="note" type="text" class="form-control" style="width: 800px;"></textarea>
						</div>
					</div>

					<div class="row">
						<div class="form-group col-sm-8 col-md-10">
							<label class="form-label">状态</label>
							<select id="status" class="custom-select">
								<option value="已启用">已启用</option>
								<option value="已停用">已停用</option>
							</select>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- table end -->
	<footer class="navbar-fixed-bottom" style="line-height: 10px;font-size:13px;">
		<div class="footer">
			© 2019 Hyhyhyhyhyhyh
		</div>
	</footer>

	<script type="text/javascript" src="{% static 'js/lib/jquery/jquery.min.js' %}"></script>
	<script type="text/javascript" src="{% static 'js/lib/bootstrap/js/bootstrap.min.js' %}"></script>

	<script type="text/javascript" src="{% static 'CodeMirror/lib/codemirror.js' %}"></script>
	<script type="text/javascript" src="{% static 'CodeMirror/mode/sql.js' %}"></script>

	<script>
		$(function () {
			var textarea = document.getElementById('code');
			var editor = CodeMirror.fromTextArea(textarea, {
				lineNumbers: true,
				autofocus: true,
				mode: 'text/x-plsql',
				theme: 'eclipse',
				matchBrackets: true,
				autoCloseBrackets: true,
				extraKeys: {
					"Ctrl": "autocomplete"
				},
			});
			editor.setSize('1000px', 'auto');


			$("#commit").on("click", function () {
				//获取检核逻辑代码框中修改后的value
				editor.save();
				var code = document.getElementById("code").value;
				var code = editor.getValue();

				//获取每个标签中的value,更新至数据库中
				var check_item = document.getElementById("check_item").value;
				var target_table = document.getElementById("target_table").value;
				var select_risk_market = document.getElementById("risk_market");
				var risk_market = select_risk_market.value;
				var problem_type = document.getElementById("problem_type").value;
				var db = document.getElementById("db").value;
				var note = document.getElementById("note").value;
				var select_status = document.getElementById("status");
				var status = select_status.value;
				//更新数据库
				$.ajax({
					type: "POST",
					url: "../rule_add",
					data: {
						source_system: "{{ source_system }}",
						check_item: check_item,
						target_table: target_table,
						risk_market: risk_market,
						problem_type: problem_type,
						db: db,
						code: code,
						note: note,
						status: status,
					},
					success: function (data) {
						console.log(data);
						alert("检核规则添加成功，正在返回上一页...");
						window.location.replace(
							'../rule_list?name={{ source_system }}&risk_market=');
					},
					error: function (e) {
						console.log(e);
						alert("发生错误");
					}
				})
			});
		});
	</script>

</body>

</html>